package rsj.api.menu;

import com.rlyy.aibase.db.Dbink;
import com.rlyy.aibase.utils.base.Box;
import com.rlyy.aibase.utils.base.MapNode;
import com.rlyy.aibase.utils.base.ThinkException;
import common.util.BoxUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import rsj.api.user.BaseLink;
import rsj.db.PostgresqlConn;
import rsj.service.MenuInfoService;

import java.sql.Connection;
import java.sql.SQLException;
@RestController
public class MenuAuthForRole extends BaseLink{
	private static MenuInfoService menuInfoService = MenuInfoService.getInstance();

	@RequestMapping(value = "rsj_sys_menuAuth")
	public Box executeLink(Box in) throws ThinkException {

	MapNode data = in.getMapNode("data");
	Connection conn = PostgresqlConn.getConnection();
	MapNode map ;
	try {
		map = menuInfoService.findMenuForRole(conn, data);
	} catch (SQLException e) {
		logger.error("invoke--->" + in.getApi() + " error "
                + ", arguments is " + in.toJson() , e);
        //return BoxUtil.errorBox(in,  "错误原因::" + e.getMessage());
        return BoxUtil.errorBox(in,  "服务器忙！" );
	}finally {
		Dbink.close(conn);
	}


	return BoxUtil.successBox(in, "查询成功！").putMapNode("data", map);
}


}
